var db = require("../util/DataBase.js");

module.exports = {
  getDeviceList(userId, success, error) {

    db.query("SELECT `id`, `push_device_id`, `user_id` FROM `device` WHERE `user_id` = ?", [
      userId
    ], function (err, results) {
      if(err) {
        error(-1, "获取设备列表失败");
      } else {
        success(results);
      }
    });

  },
  hasDeviceByPushDeviceId(deviceId, userId, success, error) {

    db.query("SELECT `id` FROM `device` WHERE `push_device_id` = ? AND `user_id` = ?", [
      deviceId,
      userId
    ], function (err, results) {
      if(err) {
        error(-1, "获取设备失败");
      } else {
        success(results.length > 0);
      }
    });

  }
}
